import { hasToken } from '@/utils/storage'
import React from 'react'
import { Route, Redirect } from 'react-router-dom'

export default function AuthRoute({ component: Component, ...reset }) {
  return (
    <Route
      {...reset}
      render={(props) => {
        // console.log(props)
        if (hasToken()) {
          return <Component></Component>
        }
        return (
          <Redirect
            to={{
              pathname: '/login',
              state: {
                from: props.location.pathname,
              },
            }}
          ></Redirect>
        )
      }}
    ></Route>
  )
}
